# Contributor: Josip <bpisoj@gmail.com>

_realname=PyICU
pkgbase=mingw-w64-python-icu
pkgname=("${MINGW_PACKAGE_PREFIX}-python-icu")
provides=("${MINGW_PACKAGE_PREFIX}-python3-icu")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-icu")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-icu")
pkgver=2.5
pkgrel=1
pkgdesc="Python extension wrapping the ICU C++ API (mingw-w64)"
arch=('any')
license=('BSD')
url="https://github.com/ovalhub/pyicu"
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-icu")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('staticlibs' 'strip' '!debug')
source=("https://pypi.io/packages/source/P/${_realname}/${_realname}-${pkgver}.tar.gz"
        001-icu-config.patch
        002-fix-mingw-build.patch)
sha256sums=('a120b68c53f769f37bfb70b7e84ca12c3f4ab1e4df43e87a02dff05ae472cdbc'
            '5d2ac5d95096a78b4d853254a199286284df6032c63e716c158c8d049c2cd41e'
            '3e8f619363b3f5b89d2e4c99432b378ba3578e7d9ef6dd6f6aa920a2cee84e1d')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -p1 -i ${srcdir}/001-icu-config.patch
  patch -p1 -i ${srcdir}/002-fix-mingw-build.patch
}

build() {
  CFLAGS+=" -fpermissive"
  #export PYICU_CFLAGS="-DPYICU_VER=\"${pkgver}\""
  export PYICU_LFLAGS="-L${MINGW_PREFIX}/lib"
  export PYICU_INCLUDES="${MINGW_PREFIX}/include"
  export PYICU_LIBRARIES="icuin;icuuc;icudt"

  # Build python module
  cd "${srcdir}/${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/python setup.py install \
      --prefix=${MINGW_PREFIX#\/} \
      --root="${pkgdir}" \
      --optimize=1 \
      --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-icu/COPYING"
}
